#coding:utf-8

#继承  class 子类名(父类名)：
#super:  super(子类名，self)。xxx
#__str__:print(实例名)时可以直接打印return里的信息
#__getattr__:调用的属性或方法不存在时返回相关信息
#__setattr__:拦截当前类中不存在的属性与值(?)
#__call__:将一个类变成一个函数

class Parent(object):
    def __init__(self,name,sex):
        self.name=name
        self.sex=sex

    def __str__(self):
        return '这是__str__函数'

    def __getattr__(self, item):
        print('这个key：%s 不存在' %item)

    def __setattr__(self, key, value):
        self.__dict__[key]=value
        print(self.__dict__)

    def __call__(self, a):
        print('call func will start')
        print(a)

    def test(self):
        print('Parent testing-------')

    def talk(self):
        print(f'{self.name} is talking')

    def is_sex(self):
        if self.sex=='male':
            print(f'{self.name} is a male')
        else:
            print(f'{self.name} is a female')

class Test(object):
    def test(self):
        print('Test testing-------')

class ChildOne(Parent,Test):
    def play_football(self):
        print(f'{self.name} is playing football')

    def talk(self):
        super(ChildOne,self).talk()
        print('child talked over')


p=Parent(name='father', sex='male')
c1=ChildOne(name='child1', sex='female')
p.is_sex()
c1.is_sex()  #子类可以调用父类方法
p.talk()
c1.talk()
c1.test()  #Parent和Test中都有test函数 因为P在前  所以调用P的test
print(ChildOne.__mro__)  #打印继承顺序
print(c1)
c1.aa
c1.name='qwq'
c1('call func')